package com.lr.controller;

import com.lr.Service.INetservice;
import com.lr.dao.Product.ProductDao;
import com.lr.dao.User.UserDao;
import com.lr.domain.INetSaler;
import com.lr.domain.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/user")
public class controller {
    @Autowired
    UserDao userDao;
    @Autowired
    ProductDao productDao;
    @Autowired
    INetservice iNetservice;
    @RequestMapping(value = "/test4")
    public String test4(@RequestParam int Oldid, int number, String INet_name,  String password, String mg_name, String tele_number)
    {
        iNetservice.change_info(Oldid,number,INet_name,password,mg_name,tele_number);
      return "redirect:/user/test3";
    }
    @RequestMapping(value = "/test3")

    public ModelAndView test3(ModelAndView modelAndView)
    {
        List<INetSaler> list=iNetservice.find_all();
        modelAndView.addObject("info",list);
        modelAndView.setViewName("user_list");


        return modelAndView;
    }
    @RequestMapping(value = "/test2")
    public String test2(@RequestParam String name, @RequestParam  String password)
    {
       System.out.println(name);
       System.out.println(password);
       if (userDao.getUser(name,password))
       {
           return "redirect:/user/test1";
       }
       else
        {
            return "1";

        }


    }
    @RequestMapping(value = "/test1")
    public ModelAndView test1(ModelAndView modelAndView)
    {
        List<Product> list=productDao.ListProduct();
        modelAndView.addObject("products",list);
        modelAndView.setViewName("listProduct");

        return modelAndView;
    }

}
